<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<#include "lib/lib.html" />
<title>新增区域</title>
</head>
<body>
<div class="pd-20">
	<form action="${basePath}/area/addArea.do" method="post"  class="form form-horizontal" id="form-area-add">
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>级别：</label>
			<div class="formControls col-5"> <span class="select-box" >
				<select class="select" id="areaLevel" name="areaLevel" nullmsg="请选择">
					<option value="" selected="selected">请选择</option>
					<option value="1" >省份</option>
					<option value="2" >城市</option>
					<option value="3" >区</option>
					<option value="4" >街道</option>
				</select>
			</span> 
			</div>
			<div class="col-3"> </div>
		</div>
		<div class="row cl" id="area">
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>名称：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" value="" placeholder="" id="areaName" name="areaName" datatype="*2-60" nullmsg="名称不能为空">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>经度：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" value="" placeholder="" id="longitude" name="longitude" datatype="*2-60" nullmsg="经度不能为空">
			</div>
			<div class="col-4"> </div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>纬度：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" value="" placeholder="" id="latitude" name="latitude" datatype="*2-60" nullmsg="纬度不能为空">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<input class="btn btn-primary radius" type="button" onclick="test()"  value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">
function test(){
	var areaLevel = $("#areaLevel").val();
	if(areaLevel == ""){
		layer.msg('请选择级别', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	var fid = $("#fid").val();
	if(areaLevel != 1 && fid == ""){
		layer.msg('请选择对应的区域', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	var areaName = $("#areaName").val();
	var longitude = $("#longitude").val();
	var latitude = $("#latitude").val();
	if(areaName == null || areaName == ""){
		layer.msg('名称不能为空', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	if(longitude == null || longitude == ""){
		layer.msg('经度不能为空', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	if(latitude == null || latitude == ""){
		layer.msg('纬度不能为空', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	$.ajax({
		type:"POST",
		url:"${basePath}/area/addArea.do",
		data:{areaLevel:areaLevel,
			fid:fid,
			areaName:areaName,
			longitude:longitude,
			latitude:latitude},
		dataType:"json",
		success:function(data){
			if(data.resultCode==200){
				window.parent.location.href="${basePath}/area/list.do";
				layer_close();
			}else{
				layer.msg('保存失败，请你检查数据!', {
					icon : 1,
					time : 1000
				});
			}
		}
	});
}
$(function(){
	$("#areaLevel").change(function(){
		var areaLevel = $("#areaLevel").val();
		var name = areaLevel==2 ? '省' : areaLevel ==3 ? '市' : '区'
		$(".divarea").remove();
		if(areaLevel != "" && areaLevel != 1){
			$.ajax({
				type:"GET",
				url:"${basePath}/area/findList.do",
				data:{areaLevel:areaLevel-1},
				dataType:"json",
				success:function(data){
					if(data.resultCode == 200){
						var list = data.Data;
						var s = "<div class='divarea'><label class='form-label col-3'><span class='c-red'>*</span>"+name+"</label><div class='formControls col-5'>"+
						"<span class='select-box' ><select class='select' id='fid' name='fid' ><option value='' selected='selected'>请选择</option>"+
						" </select></span></div><div class='col-3'> </div></div>";
						$("#area").append(s);
						for(var i=0;i<list.length;i++){
							$("#fid").append("<option value="+list[i].id+">"+list[i].areaName+"</option>");
						}
					}				
				}
			});
		}
	});
});
</script>
</body>
</html>